package com.hongye.app.model;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hongye.util.JsonUtils;
import com.hongye.util.Utils;
import com.jfinal.plugin.activerecord.Model;

public class OrderTracesModel extends Model<OrderTracesModel>{
	private static final long serialVersionUID = -5317310510318889388L;
	public static final OrderTracesModel dao = new OrderTracesModel();
	
	/**
	 * 获取最新物流信息（当前最新一条数据）
	 * @author lifuqiang
	 * 2016-11-18
	 * @param waybillnumber
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static Map<String, Object> getNewTraces(String waybillnumber){
		Map<String, Object> map_traces = new HashMap<String, Object>();
		String sql3 = "select * from order_traces where waybillnumber = '"+waybillnumber+"'";
		OrderTracesModel returngoods = OrderTracesModel.dao.findFirst(sql3);
		String data = returngoods.get("data");
		if(data!=null){
			Map<String, Object> map = JsonUtils.deserialize(data);
			List<Map<String, Object>> traces = (List<Map<String, Object>>) map.get("Traces");
			if(traces.size()==0){
				map_traces.put("AcceptStation", "暂无物流信息！");
				map_traces.put("AcceptTime", Utils.getDate());
			}else{
				map_traces = traces.get(traces.size()-1);
			}
		}else{
			map_traces.put("AcceptStation", "该包裹正在被揽件！");
			map_traces.put("AcceptTime",  Utils.getDate());
		}
		return map_traces;
	}
}
